import java.util.Scanner;

public class RomanTime {
	// 符號轉數值
	public static int value(char romanToken) {
		switch(romanToken) {
		case 'I':
			return 1;
		case 'V':
			return 5;
		case 'X':
			return 10;
		}
		return 50;
	}
	// 數值轉符號
	public static String[][] token = {	{"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"},
																	{"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"} };
	// 數值加總成時間
	public static int calculator(char[] tokens) {
		int time = value(tokens[tokens.length - 1]);
		for(int i = 0; i < (tokens.length - 1); i++) {
			if( (value(tokens[i]) < value(tokens[i + 1])) )
				{ time -= value(tokens[i]); }
			else
				{ time += value(tokens[i]); }
		}
		return time;
	}
	// 主程式
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String input, output;
		char[] spInput;
		int originHour, originMin;
		int TWHour, TWMin;
		int totalMin;
		
		while(sc.hasNext()) {
			// 時
			input = sc.nextLine();
			spInput = input.toCharArray();
			originHour = calculator(spInput);
			
			//分
			input = sc.nextLine();
			spInput = input.toCharArray();
			originMin = calculator(spInput);
			
			// 總時間 + 誤差
			totalMin = ( ((originHour * 60) + originMin) + 450 );
			if(totalMin > 1440)
				{ totalMin -= 1440; }
			
			TWHour = (totalMin / 60);
			TWMin = (totalMin % 60);

			// 時
			output = "";
			int temp = 10;
			for(int i = 1; i >= 0; i--) {
				output += token[i][TWHour / temp];
				TWHour %= temp;
				temp /= 10;
			}
			System.out.println(output);
			
			// 分
			output = "";
			temp = 10;
			for(int i = 1; i >= 0; i--) {
				output += token[i][TWMin / temp];
				TWMin %= temp;
				temp /= 10;
			}
			System.out.println(output);
		}
	}
}